/*
 * @(#)CapturePlayback.java	1.11	99/12/03
 *
 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

/** 
 * The HelloWorldApp class implements an application that
 * simply prints "Hello World!" to standard output.
 */


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Line2D;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.Vector;
import java.util.Enumeration;
import java.io.*;
import javax.sound.sampled.*;
import java.awt.font.*;
import java.text.*;
import java.awt.Image.*;
import javax.imageio.*;
import java.awt.Toolkit;


import java.io.*;
import java.awt.BorderLayout;
import java.awt.Container ;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JSplitPane;

import java.awt.geom.Line2D;
import javax.swing.*;        
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.net.MalformedURLException;
import javax.sound.sampled.*;
import javax.sound.midi.*; 
import java.lang.Object.*;

/*
class DirTree {
	DirTree left_child;
	DirTree right_sibling;
	JButton button;

	public DirTree(JButton mybutton) {
		left_child = right_sibling;
		button = mybutton;
	}

	public DirTree insertChildAtNode(JButton mybutton) {
		dirtree = new DirTree(mybutton);
		left_child = dirtree;
		return left_child;
	}

	public DirTree insertSiblingAtNode(JButton mybutton) {
		dirtree = new DirTree(mybutton);
		right_sibling = dirtree;
		return right_sibling;
	}
};
*/



class Oldfb1 extends JPanel implements ActionListener, Runnable {
	JButton[] buttons;
	int[] drive_index;
	int last_drive_index;
	String[] drives;
	int last_button_index;
	Font font;
	Font font1;
	JButton back_button;
	JButton pdf_button;
	JButton photo_button;
	JButton movie_button;
	JButton doc_button;
	JButton all_button;
	JButton memo_button;
	JButton dir_button;
	JButton record_button;
	JButton last_clicked_file;
	String current_memo;
	String parent_dir;
	String current_dir;
	JFrame frame;
	JScrollPane pane;
	Thread thread;
	Thread memo_thread;
	int type;
	AudioInputStream audioInputStream;
	boolean lineOpen;
	JButton current_selected;
	int filetype;
	boolean showdir;
	Oldfb1 child;
	Oldfb1 sibling;
	static final int TYPE_ALL=0;
	static final int TYPE_PDF=1;
	static final int TYPE_DOC=2;
	static final int TYPE_PHOTO=3;
	static final int TYPE_MOVIE=4;

	public Oldfb1(int mytype) {
		font = new Font("Georgia",Font.PLAIN, 14);
		font1 = new Font("Georgia",Font.BOLD, 18);
		showdir = true;
		buttons = new JButton[1024];
		drives = new String[20];
		drive_index = new int[1024];
		for(int i=0; i < 1024; i++) {
			buttons[i] = new JButton();
			buttons[i].setFont(font);
		}
//		System.out.println("buttons[1] " + buttons[0]);
		type = mytype;
		current_dir = new String("C://");
		parent_dir = new String("C://");
		//makeicons();
	}
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
	public void setScrollPane(JScrollPane mypane) {
		pane = mypane;
	}

	public void setChild(Oldfb1 oldfb1) {
			child = oldfb1;
	}

	
	public void makeicons() {
	//Container content = frame.getContentPane();
	setBackground(Color.white);
    setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.HORIZONTAL;
    //back_button = new JButton("Back");
    //add(back_button);
	//back_button.addActionListener(this);
	try {

    c.anchor = GridBagConstraints.FIRST_LINE_START;
    ImageIcon cup5 = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/back_icon.jpg"));
    //ImageIcon cup5 = new ImageIcon("C://java1/back_icon.jpg");
    back_button = new JButton(cup5);
	back_button.addActionListener(this);
    	back_button.setBackground(Color.white);
	//back_button.setBorder(null);
    add(back_button,c);
    ImageIcon cup9 = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/dir_big_icon.jpg"));
    //ImageIcon cup5 = new ImageIcon("C://java1/back_icon.jpg");
    dir_button = new JButton(cup9);
	dir_button.addActionListener(this);
    	dir_button.setBackground(Color.lightGray);
    	dir_button.setText("On");
	//back_button.setBorder(null);
    add(dir_button,c);
    ImageIcon cup = new ImageIcon(new URL("http://veerex.googlecode.com/files/pdf_icon.jpg"));
    pdf_button = new JButton(cup);
	pdf_button.addActionListener(this);
    	pdf_button.setBackground(Color.white);
	//pdf_button.setBorder(null);
    add(pdf_button);
    ImageIcon cup2 = new ImageIcon(new URL("http://veerex.googlecode.com/files/docs_icon.jpg"));
    doc_button = new JButton(cup2);
	doc_button.addActionListener(this);
	//doc_button.setBorder(null);
    	doc_button.setBackground(Color.white);
//    doc_button.setHorizontalTextPosition(SwingConstants.CENTER);
    add(doc_button);	
    ImageIcon cup1 = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/photo_icon.jpg"));
    //ImageIcon cup1 = new ImageIcon(("C://java1/photo_icon.jpg"));
    photo_button = new JButton(cup1);
	photo_button.addActionListener(this);
	//photo_button.setBorder(null);
    	photo_button.setBackground(Color.white);
    //photo_button.setText("Photos");
    add(photo_button);
    ImageIcon cup6 = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/movie_icon.jpg"));
    movie_button = new JButton(cup6);
	movie_button.addActionListener(this);
	//movie_button.setBorder(null);
    	movie_button.setBackground(Color.white);
    //movie_button.setText("Movies");
    add(movie_button);
    ImageIcon cup7 = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/all_icon.jpg"));
    //ImageIcon cup7 = new ImageIcon("C://java1/all_icon.jpg");
    all_button = new JButton(cup7);
	all_button.addActionListener(this);
	//all_button.setBorder(null);
    all_button.setText("All");
//	all_button.setVerticalTextPosition(SwingConstants.BOTTOM);
//    all_button.setHorizontalTextPosition(SwingConstants.CENTER);
    	all_button.setBackground(Color.white);
    c.anchor = GridBagConstraints.FIRST_LINE_END;
    add(all_button,c);
    memo_button = new JButton(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/memo_icon.jpg")));
	memo_button.addActionListener(this);
	//memo_button.setBorder(null);
    memo_button.setText("List Memos");
    	memo_button.setBackground(Color.white);
//	memo_button.setVerticalTextPosition(SwingConstants.BOTTOM);
//    memo_button.setHorizontalTextPosition(SwingConstants.CENTER);
    c.anchor = GridBagConstraints.FIRST_LINE_END;
    add(memo_button,c);
    File f = new File("C:\\Veerex-AudioMarkers");
    if(!f.exists()) {
//	    System.out.println("C:\\Veerex-AudioMarkers does not exist, will be created ...");
    	memo_button.setEnabled(false);
    }
   ImageIcon cup8 = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/record_icon.jpg"));
    //ImageIcon cup8 = new ImageIcon("C://java/svn/veerex/src/record_icon.jpg");
    record_button = new JButton(cup8);
	record_button.addActionListener(this);
	//record_button.setBorder(null);
    record_button.setText("Record Memo");
//	record_button.setVerticalTextPosition(SwingConstants.BOTTOM);
//    record_button.setHorizontalTextPosition(SwingConstants.CENTER);
    	record_button.setBackground(Color.white);
    c.anchor = GridBagConstraints.FIRST_LINE_END;
    add(record_button,c);
    current_selected = all_button;
    } catch (MalformedURLException e) {
    }

	}

  public void setFrame(JFrame vframe) {
	  	frame = vframe;
  }

public void beginPlayMemos() {

		memo_thread = new Thread(this);
		memo_thread.setName("Memo");
		memo_thread.start();

}


  public void beginPlay(boolean save) {

	  	SourceDataLine line;
		final int bufSize = 16384;
            // reload the file if loaded by file
            //if (file != null) {
             //   createAudioInputStream(file, false);
            //}

            // make sure we have something to play
            while(audioInputStream == null) {
//                //System.out.println("No loaded audio to play back");
                //return;
            }
            // reset to the beginnning of the stream
            try {
                if(save) audioInputStream.reset();
            } catch (Exception e) {
//                System.out.println("Unable to reset the stream\n" + e);
                return;
            }

	    if(save) {
//	    	System.out.println("C://Veerex-AudioMarkers/"+child.current_dir.replace('\\','^').replace(':','-')+".wav");
	    	File file = new File("C:\\Veerex-AudioMarkers");
	    	file.mkdir();
		if(child.last_clicked_file != null)
	    	file = new File("C:\\Veerex-AudioMarkers\\"+child.current_dir.replace('\\','`').replace(':','^')+"`"+child.last_clicked_file.getText()+".wav");
		else
	    	file = new File("C:\\Veerex-AudioMarkers\\"+child.current_dir.replace('\\','`').replace(':','^')+".wav");
        	try {
	    		file.createNewFile();
            		if (AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, file) == -1) {
                		throw new IOException("Problems writing to file");
            		}
        	} catch (Exception ex) { 
			System.out.println(ex.toString()); 
		}
	}
            // get an AudioInputStream of the desired format for playback
            AudioFormat format = getFormat(true);

            AudioInputStream playbackInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);
                        
            if (playbackInputStream == null) {
//                System.out.println("Unable to convert stream of format " + audioInputStream + " to format " + format);
                return;
            }

            // define the required attributes for our line, 
            // and make sure a compatible line is supported.

            DataLine.Info info = new DataLine.Info(SourceDataLine.class, 
                format);
            if (!AudioSystem.isLineSupported(info)) {
//                System.out.println("Line matching " + info + " not supported.");
                return;
            }

            // get and open the source data line for playback.

            try {
                line = (SourceDataLine) AudioSystem.getLine(info);
                line.open(format, bufSize);
            } catch (LineUnavailableException ex) { 
//                System.out.println("Unable to open the line: " + ex);
                return;
            }

            // play back the captured audio data

            int frameSizeInBytes = format.getFrameSize();
            int bufferLengthInFrames = line.getBufferSize() / 8;
            int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
            byte[] data = new byte[bufferLengthInBytes];
            int numBytesRead = 0;

            // start the source data line
            line.start();

            while (true) {
                try {
                    if ((numBytesRead = playbackInputStream.read(data)) == -1) {
                        break;
                    }
                    int numBytesRemaining = numBytesRead;
                    while (numBytesRemaining > 0 ) {
                        numBytesRemaining -= line.write(data, 0, numBytesRemaining);
                    }
                } catch (Exception e) {
//                    System.out.println("Error during playback: " + e);
                    break;
                }
            }
            // we reached the end of the stream.  let the data play out, then
            // stop and close the line.
            //if (thread != null) {
                line.drain();
            //}
            line.stop();
            line.close();
            line = null;
        }

        public AudioFormat getFormat(boolean wav) {

/*
        	Vector groups = new Vector();
            Vector v = new Vector(groups.size());
            for (int i = 0; i < groups.size(); i++) {
                ButtonGroup g = (ButtonGroup) groups.get(i);
                for (Enumeration e = g.getElements();e.hasMoreElements();) {
                    AbstractButton b = (AbstractButton) e.nextElement();
                    if (b.isSelected()) {
                        v.add(b.getText());
                        break;
                    }
                }
            }

            AudioFormat.Encoding encoding = AudioFormat.Encoding.ULAW;
            String encString = (String) v.get(0);
            float rate = Float.valueOf((String) v.get(1)).floatValue();
            int sampleSize = Integer.valueOf((String) v.get(2)).intValue();
            String signedString = (String) v.get(3);
            boolean bigEndian = ((String) v.get(4)).startsWith("big");
            int channels = ((String) v.get(5)).equals("mono") ? 1 : 2;

            if (encString.equals("linear")) {
                if (signedString.equals("signed")) {
                    encoding = AudioFormat.Encoding.PCM_SIGNED;
                } else {
                    encoding = AudioFormat.Encoding.PCM_UNSIGNED;
                }
            } else if (encString.equals("alaw")) {
                encoding = AudioFormat.Encoding.ALAW;
            }
            return new AudioFormat(encoding, rate, sampleSize, 
                          channels, (sampleSize/8)*channels, rate, bigEndian);
	    */
		if(wav)
	    	return new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, true);
		else
	    	return new AudioFormat(AudioFormat.Encoding.ULAW, 8000, 8, 1, 1, 8000, true);
        }
  public void beginRecording() {

		thread = new Thread(this);
		thread.setName("Record");
		thread.start();
  }

  public void run() {

	  	if(Thread.currentThread() == memo_thread) {
//			System.out.println("Memo thread begins");

			File f = new File("C:\\Veerex-AudioMarkers");
			String [] files;
			String str;
			if(child.last_clicked_file == null)
				files = f.list();
			else {
				files = new String[1];
				files[0] = child.last_clicked_file.getText();
			}
//			System.out.println("Memo files = "+files.length);

			/*
			try {
		      		audioInputStream = AudioSystem.getAudioInputStream(new URL("http://veerex.googlecode.com/svn/trunk/src/welcome_msg.wav"));
            		} catch (Exception ex) { 
//                			System.out.println(ex.toString());
            		}
			beginPlay(false);
			*/

			for(int i=0; (i < files.length) && (memo_thread!=null); i++) {
				current_memo = new String(files[i].replace('^',':').replace('`','\\'));
				str = new String(files[i]);
//				System.out.println(current_memo);

				try {
				audioInputStream = AudioSystem.getAudioInputStream(new File(f.getAbsolutePath() + "\\"+str));
				beginPlay(false);
				audioInputStream.close();
            			} catch (Exception ex) { 
//                			System.out.println(ex.toString());
            			}

				/*
				try {
					if(i == files.length-1)
		      		audioInputStream = AudioSystem.getAudioInputStream(new URL("http://veerex.googlecode.com/svn/trunk/src/goodbye_msg.wav"));
					else
		      		audioInputStream = AudioSystem.getAudioInputStream(new URL("http://veerex.googlecode.com/svn/trunk/src/next_msg.wav"));
            			} catch (Exception ex) { 
//                			System.out.println(ex.toString());
            			}
				beginPlay(false);
				*/
				/*
		      	try{
     				Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+"C:\\Veerex-AudioMarkers\\"+str);
				p.wait();
    			} catch (Exception e) {
//				System.out.println("exception in memo thread"+e.toString());
    			}
			*/
			}
//			System.out.println("Memo thread ends");
			try {
			record_button.setText("Delete Memo");
		      	record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/delete_icon.jpg")));
		      		memo_button.setText("Play Memos");
		      		memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/play_icon.jpg")));
    				} catch (MalformedURLException e) {
    				}
			return;
		}


	  	TargetDataLine line;
		double duration;
		audioInputStream  = null;
            AudioFormat format = getFormat(true);
            DataLine.Info info = new DataLine.Info(TargetDataLine.class, 
                format);
                        
//	    System.out.println("recording thread starts");
            if (!AudioSystem.isLineSupported(info)) {
//                System.out.println("Line matching " + info + " not supported.");
                return;
            }

            // get and open the target data line for capture.

            try {
                line = (TargetDataLine) AudioSystem.getLine(info);
                line.open(format, line.getBufferSize());
            } catch (LineUnavailableException ex) { 
//                System.out.println("Unable to open the line: " + ex);
                return;
            } catch (SecurityException ex) { 
//                System.out.println(ex.toString());
                JavaSound.showInfoDialog();
                return;
            } catch (Exception ex) { 
//                System.out.println(ex.toString());
                return;
            }

            // play back the captured audio data
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int frameSizeInBytes = format.getFrameSize();
            int bufferLengthInFrames = line.getBufferSize() / 8;
            int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
            byte[] data = new byte[bufferLengthInBytes];
            int numBytesRead;
            
            line.start();

            while (thread != null) {
                if((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
                    break;
                }
                out.write(data, 0, numBytesRead);
            }

            // we reached the end of the stream.  stop and close the line.
            line.stop();
            line.close();
            line = null;

            // stop and close the output stream
            try {
                out.flush();
                out.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }

            // load bytes into the audio input stream for playback

            byte audioBytes[] = out.toByteArray();
            ByteArrayInputStream bais = new ByteArrayInputStream(audioBytes);
            AudioInputStream myaudioInputStream = new AudioInputStream(bais, format, audioBytes.length / frameSizeInBytes);

            long milliseconds = (long)((myaudioInputStream.getFrameLength() * 1000) / format.getFrameRate());
            duration = milliseconds / 1000.0;

            try {
                myaudioInputStream.reset();
            } catch (Exception ex) { 
                ex.printStackTrace(); 
                return;
            }

	    audioInputStream = myaudioInputStream;
//	    System.out.println("recording thread ends"+audioInputStream);
  }

/*
private Image createThumbnail(Image image) {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();
    
    int thumbWidth = 64;
    int thumbHeight = -1;
    
    if (thumbHeight == -1)
        thumbHeight = thumbWidth * sourceHeight / sourceWidth;
    
    Image thumb = Image.createImage(thumbWidth, thumbHeight);
    Graphics g = thumb.getGraphics();
    
    for (int y = 0; y < thumbHeight; y++) {
        for (int x = 0; x < thumbWidth; x++) {
            g.setClip(x, y, 1, 1);
            int dx = x * sourceWidth / thumbWidth;
            int dy = y * sourceHeight / thumbHeight;
            g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
        }
    }
    
    Image immutableThumb = Image.createImage(thumb);
    
    return immutableThumb;
}
*/

		public void listfiles(String a) {

		JButton buttons_i;

//			System.out.println("type="+type);
		if(type==2) {
    			setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
			buttons_i= new JButton();
			buttons_i.addActionListener(this);
			try {
    			ImageIcon cupdrive = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/drive_icon.jpg"));
    			buttons_i.setIcon(cupdrive);
    } catch (MalformedURLException e) {
    }
    			buttons_i.setText(a);
			buttons_i.setFont(font1);
			buttons_i.setForeground(Color.RED);
			//buttons_i.setHorizontalTextPosition(SwingConstants.LEFT);
			buttons_i.setBorder(null);
			buttons_i.setBackground(this.getBackground());
			buttons_i.setContentAreaFilled(false);
    			add(buttons_i);
			//buttons_i.setFont(font);
		}
		else {
    			//setLayout(new GridLayout(0,2));
    			setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		}
    	setBackground(Color.white);
	//String a = "C:\\java";
	int i,j;
	File f = new File(a);
	String [] files;	
	String mline = new String();
	if(!f.exists()) {
		last_drive_index++;
		System.out.println("empty drive "+a);
		return;
	}
	files = f.list();
//	System.out.println(a);
//	System.out.println(files.length);
	//mline = mline.concat("<html><body><br><br><br>");
        JLabel label = new JLabel("Veeru");
	/*
	label.setText("Hellow World\n");
        frame.getContentPane().add(label);
	label.setText("<html><body> This is a new HTML string <br> <br></body></html>");
        frame.getContentPane().add(label);
	label.setText("<html><body> And This is one more HTML string <br> <br></body></html>");
        frame.getContentPane().add(label);
	*/
	//label.setText("<br>");
	//label.setText("<br>");
        //add(label);
	//
		if(f.isDirectory()) {
			//JButton buttons_i = new JButton();
    			//buttons_i.setText("Back");
//			System.out.println(f.getName());
//			System.out.println(f.getParent());
			current_dir = new String(f.getAbsolutePath());
			frame.setTitle("VeerExplorer - "+current_dir);
			if(f.getParent() != null) {
				parent_dir = f.getParentFile().getAbsolutePath();
				//buttons_i.addActionListener(this);
			//buttons_i.setBorder(null);
			//buttons_i.setBackground(this.getBackground());
			//buttons_i.setContentAreaFilled(false);
    				//add(buttons_i);
			}
			else {
//				System.out.println("No parent");
				parent_dir = null;
			}
		}
		
	for(j=last_button_index,i=0; (files != null) && (i < files.length); j++,i++) {
		File f1 = new File(f.getAbsolutePath() + "\\"+files[i]);
//		System.out.println("file name ="+f.getAbsolutePath()+"\\"+files[i]);
		ImageIcon  cup;
			try {
		if(f1.isDirectory()) {
			if(!showdir)
				continue;
			if((type==2) && (j < 1024))
				buttons_i = buttons[j];
			else
				buttons_i = new JButton();

			drive_index[j] = last_drive_index;
		//	System.out.println("drive_index[i]="+drive_index[i]+" "+i);
    			cup = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/dir_icon.jpg"));
    			//cup = new ImageIcon("C://java1/dir_icon.jpg");
			buttons_i.addActionListener(this);
    			buttons_i.setIcon(cup);
    			buttons_i.setText(files[i]);
			//buttons_i.setHorizontalTextPosition(SwingConstants.LEFT);
			buttons_i.setBorder(null);
			buttons_i.setBackground(this.getBackground());
			buttons_i.setContentAreaFilled(false);
    			add(buttons_i);
			buttons_i.setFont(font);
		}
		else if(type==3){
			int cmderr=0;
			String ext = files[i].substring(files[i].lastIndexOf('.')+1);
//			System.out.println(ext);
		try {
     			Process p = Runtime.getRuntime().exec("assoc "+ext);
		} catch (Exception e) {
			cmderr=1;
    		}
		//if(cmderr == 0) {
//			//System.out.println("assoc succeeded");
			boolean mismatch=false;
			switch(filetype) {
				case TYPE_PHOTO:
					if( (ext.compareTo("jpg") != 0) && (ext.compareTo("JPG") != 0) && (ext.compareTo("gif")!=0) && ((ext.compareTo("jpeg")!=0)) )
						mismatch=true;
					break;
				case TYPE_MOVIE:
					if( (ext.compareTo("avi") != 0) && (ext.compareTo("mpg")!=0) )
						mismatch=true;
					break;
				case TYPE_PDF:
					if(ext.compareTo("pdf") != 0)
						mismatch=true;
					break;
				case TYPE_DOC:
					if(ext.compareTo("doc") != 0)
						mismatch=true;
					break;
				default:
						break;
			}

			if(mismatch)
				continue;
					/* fall through */
			//	cup = new ImageIcon("C://java1/photos_icon_small.jpg");
			if( (ext.compareTo("jpg") == 0) || (ext.compareTo("JPG") == 0) || (ext.compareTo("gif")==0) || ((ext.compareTo("jpeg")==0)) ) {
				//Image redball = Toolkit.getDefaultToolkit().getImage(files[i]);
				//Image thumbnail = createThumbnail(redball);
				//cup = new ImageIcon(thumbnail);
				cup = new ImageIcon(new URL("http://veerex.googlecode.com/files//photos_icon_small.jpg"));
			}
			else if( (ext.compareTo("avi") == 0) || (ext.compareTo("mpg")==0) || (ext.compareTo("mpeg")==0) )
				cup = new ImageIcon(new URL("http://veerex.googlecode.com/files//photos_icon_small.jpg"));
			else if( (ext.compareTo("pdf")==0))
			//	cup = new ImageIcon(("C://java1/pdf_icon_small.gif"));
				cup = new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/pdf_icon_small.gif"));
			else if( (ext.compareTo("doc")==0))
				//cup = new ImageIcon(("C://java1/docs_icon_small.jpg"));
				cup = new ImageIcon(new URL("http://veerex.googlecode.com/files//docs_icon_small.jpg"));
			else
				cup = new ImageIcon(new URL("http://veerex.googlecode.com/files//file_icon.jpg"));
		//}
			if(i < 0)
				buttons_i = buttons[i];
			else
				buttons_i = new JButton();

			buttons_i.addActionListener(this);
    			buttons_i.setText(files[i]);
			buttons_i.setBorder(null);
			buttons_i.setBackground(this.getBackground());
			//buttons_i.setHorizontalTextPosition(SwingConstants.LEFT);
			buttons_i.setContentAreaFilled(false);
//			//System.out.println(i);
    			buttons_i.setIcon(cup);
    			add(buttons_i);
			buttons_i.setFont(font);
		}
		//mline = mline.concat(files[i]);
//		//System.out.println(files[i]);
		//mline = mline.concat("<br>");
		//mline = mline.concat("\n");
        	//label.setText(files[i]);
        	//add(label);
    } catch (MalformedURLException e) {
    }

    			if(i%20 == 0) {
				validate();
				pane.revalidate();
				pane.repaint();
			}	

	}
	if(type == 2) {
		last_button_index=j;
		last_drive_index++;
		System.out.println("last_drive_index="+last_drive_index+"button_index="+last_button_index);
	}
	if(files.length == 0) {
        label = new JLabel("Empty Folder");
	label.setForeground(Color.BLUE);
	add(label);
	}
        	//label.setText("EOF");
        	//add(label);
		validate();
		pane.revalidate();
		pane.repaint();
//		System.out.println("Done listing");
	/*
	for(i=files.length; i < 1024; i++) {
		buttons_i.setText(null);
		buttons_i.setBorder(null);
		buttons_i.setContentAreaFilled(false);
		add(buttons_i);
	}
	*/

	//mline = mline.concat("</body></html>");
	//label.setText("<html><body>first line<br>second line<br>third line<br></body></html>");
        	//add(label);

//	//System.out.println(mline);
        	//label.setText(mline);
		//textarea.append(mline);
        	//add(label);
		}

    private static void createAndShowGUI() {
	    int i;
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JButtons frame = new JButtons("Veeru File Browser");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
    WindowUtilities.setNativeLookAndFeel();
    frame.setSize(400, 150);
    Container content = frame.getContentPane();
    content.setBackground(Color.white);
    content.setLayout(new FlowLayout()); 
    //content.add(new JButton("Button 1"));
    //content.add(new JButton("Button 2"));
    //content.add(new JButton("Button 3"));
    frame.makeButtons(frame);
    frame.addWindowListener(new ExitListener());
    frame.setVisible(true);
	//frame.setBounds(350,300,100,100);

//    JPanel drawingArea = new JPanel();
    // Preferred height is irrelevant, since using WEST region
 //   drawingArea.setPreferredSize(new Dimension(400, 0));
  //  drawingArea.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
   // drawingArea.setBackground(Color.white);
    //drawingArea.
   // frame.getContentPane().add(drawingArea, BorderLayout.WEST);

        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Veeru");

	VeryOldfb ofb = new VeryOldfb();	
	ofb.ShowFiles(frame);

	String a = "C:\\";
	File f = new File(a);
	String [] files;	
	String mline = new String();
	files = f.list();
	mline = mline.concat("<html><body><br><br><br>");
	/*
	label.setText("Hellow World\n");
        frame.getContentPane().add(label);
	label.setText("<html><body> This is a new HTML string <br> <br></body></html>");
        frame.getContentPane().add(label);
	label.setText("<html><body> And This is one more HTML string <br> <br></body></html>");
        frame.getContentPane().add(label);
	*/
	label.setText("<br>");
        frame.getContentPane().add(label);
	for(i=0; i < files.length; i++) {
		mline = mline.concat(files[i]);
//		//System.out.println(files[i]);
		mline = mline.concat("<br>");
        	label.setText(files[i]);
        	frame.getContentPane().add(label);
        	label.setText("<br>");
        	frame.getContentPane().add(label);
	}
	mline = mline.concat("</body></html>");
	label.setText("<html><body>first line<br>second line<br>third line<br></body></html>");
        	frame.getContentPane().add(label);

//	//System.out.println(mline);
        	label.setText(mline);
        	frame.getContentPane().add(label);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

 public void actionPerformed(ActionEvent evt)
         {
  // Here we will ask what component called this method
 		File f=null; 
		String str=null;
		boolean openfile=false, dirmenu=false, icon_menu=false;
		Oldfb1 comp;

//		System.out.println("button clicked");
              if(((JButton)evt.getSource())==back_button) {
			record_button.setText("Record Memo");
				try {
		      			record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/record_icon.jpg")));
		      			//memo_button.setText("List All Memos");
		      			memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/memo_icon.jpg")));
		      			memo_button.setText("List Memos");
    				} catch (MalformedURLException e) {
    				}
		      if(child.parent_dir != null)
		      	str = new String(child.parent_dir);
		      else 
			str = new String("C:\\");
		      f = new File(str);
		      //current_selected.setBackground(this.getBackground());
//		      System.out.println("action parent"+str);
	      }
	      else if(((JButton)evt.getSource())==dir_button) {
		      str = new String(child.current_dir);
		      f = new File(str);
//		      System.out.println("action current"+str);
		      //current_selected.setBackground(this.getBackground());
		      //current_selected = dir_button;
		      if(dir_button.getBackground().equals(Color.lightGray)) {
		      	dir_button.setBackground(this.getBackground());
    			dir_button.setText("Off");
		      	child.showdir = false;
		      }
		      else {
		      	dir_button.setBackground(Color.lightGray);
    			dir_button.setText("On");
		      	child.showdir = true;
		      }
	      }
	      else if(((JButton)evt.getSource())==pdf_button) {
		      	str = new String(child.current_dir);
		      f = new File(str);
//		      System.out.println("action current"+str);
		      current_selected.setBackground(this.getBackground());
		      current_selected = pdf_button;
		      current_selected.setBackground(Color.lightGray);
		      child.filetype=Oldfb1.TYPE_PDF;
	      		}
	      else if(((JButton)evt.getSource())==photo_button) {
		      	str = new String(child.current_dir);
		      f = new File(str);
		      current_selected.setBackground(this.getBackground());
		      current_selected = photo_button;
		      current_selected.setBackground(Color.lightGray);
		      child.filetype=Oldfb1.TYPE_PHOTO;
	      }
	      else if(((JButton)evt.getSource())==movie_button) {
		      	str = new String(child.current_dir);
		      f = new File(str);
		      current_selected.setBackground(this.getBackground());
		      current_selected = movie_button;
		      current_selected.setBackground(Color.lightGray);
		      child.filetype=Oldfb1.TYPE_MOVIE;
	      }
	      else if(((JButton)evt.getSource())==doc_button) {
		      	str = new String(child.current_dir);
		      f = new File(str);
		      current_selected.setBackground(this.getBackground());
		      current_selected = doc_button;
		      current_selected.setBackground(Color.lightGray);
		      child.filetype=Oldfb1.TYPE_DOC;
	      }
	      else if(((JButton)evt.getSource())==all_button) {
		      	str = new String(child.current_dir);
		      f = new File(str);
		      current_selected.setBackground(this.getBackground());
		      current_selected = all_button;
		      current_selected.setBackground(Color.lightGray);
		      child.filetype=Oldfb1.TYPE_ALL;
	      }
     		else if(((JButton)evt.getSource())==memo_button) {
			if(((JButton)evt.getSource()).getText().equals("Play Memos")) {
		      		//lineOpen = false;
//		      		//System.out.println("lineOpen="+lineOpen);
	    			//thread = null;
				record_button.setText("Go!");
    				record_button.setEnabled(true);
				memo_button.setText("Stop Memo");
				try {
		      		record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/go_icon.jpg")));
//	    			//System.out.println(new String(child.current_dir));
				beginPlayMemos();
				//try {
				//memo_thread.join();
    				//} catch (Exception e) {
    				//}

    				} catch (MalformedURLException e) {
    				}
		      		return;
			}
			else if(((JButton)evt.getSource()).getText().equals("Stop Memo")) {
				memo_thread=null;
				record_button.setText("Record Memo");
				try {
		      			record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/record_icon.jpg")));
		      			//memo_button.setText("List All Memos");
		      			memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/memo_icon.jpg")));
		      			memo_button.setText("List Memos");
    				} catch (MalformedURLException e) {
    				}
				return;
			}
			else if(((JButton)evt.getSource()).getText().equals("List Memos")) {
		      	str = new String("C://Veerex-AudioMarkers");
		      f = new File(str);
		      //current_selected.setBackground(this.getBackground());
		      //current_selected = memo_button;
		      //current_selected.setBackground(Color.lightGray);
		      memo_button.setText("Play Memos");
			record_button.setText("Delete Memo");
    			record_button.setEnabled(true);
		      try {
		      record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/delete_icon.jpg")));
		      memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/play_icon.jpg")));
    				} catch (MalformedURLException e) {
    				}
		      child.filetype=Oldfb1.TYPE_ALL;
	      }
		}
	      else if(((JButton)evt.getSource()).getText().equals("Record Memo")) {
		      /* lineOpen is a toggle switch */
		      	lineOpen = true;
//		      System.out.println("lineOpen="+lineOpen);
		      	beginRecording();
			record_button.setText("Stop");
		      return;
	      }
	      else if(((JButton)evt.getSource()).getText().equals("Delete Memo")) {
		      if(child.last_clicked_file != null) {
			str = new String("C://Veerex-AudioMarkers//"+child.last_clicked_file.getText());
		      	f = new File(str);
		      	System.out.println("file "+str+"deleted ?"+f.delete());
		      }
			str = new String("C://Veerex-AudioMarkers");
		      f = new File(str);
		      current_selected.setBackground(this.getBackground());
		      current_selected = memo_button;
		      current_selected.setBackground(Color.lightGray);
		      memo_button.setText("Play Memos");
			record_button.setText("Delete Memo");
    			record_button.setEnabled(true);
		      try {
		      record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/delete_icon.jpg")));
		      memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/play_icon.jpg")));
    				} catch (MalformedURLException e) {
    				}
		      child.filetype=Oldfb1.TYPE_ALL;	      

	      }
	      else if(((JButton)evt.getSource()).getText().equals("Stop")) {
		      str=null;
		      if(lineOpen) {
		      	lineOpen = false;
//		      System.out.println("lineOpen="+lineOpen);
	    		thread = null;
			beginPlay(true);
    			memo_button.setEnabled(true);
			record_button.setText("Record Memo");
			try {
		      	record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/record_icon.jpg")));
    				} catch (MalformedURLException e) {
    				}
//	    		System.out.println(new String(child.current_dir));
		      	return;
		      }
	      }
	      else if(((JButton)evt.getSource()).getText().equals("Go!")) {
			openfile=true;
			icon_menu=true;
			Thread mthread = memo_thread;
			memo_thread = null;
				try {
				mthread.join();
    				} catch (Exception e) {
    				}
		        str = current_memo.replace('`','\\').replace('^',':');
			str = str.substring(0,str.lastIndexOf(".wav"));
//			System.out.println("Selected Memo="+str);
			record_button.setText("Record Memo");
			try {
		      record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/record_icon.jpg")));
		      	memo_button.setText("List Memos");
		      memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/memo_icon.jpg")));
    				} catch (MalformedURLException e) {
    				}
		}
		else {
			openfile=true;
    			//record_button.setEnabled(true);
			if(type==3) {
		      str = new String(current_dir +"\\" + ((JButton)evt.getSource()).getText());
			}
			else if(type==2){
				sibling.record_button.setText("Record Memo");
				try {
		      			sibling.record_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/record_icon.jpg")));
		      			//memo_button.setText("List All Memos");
		      			sibling.memo_button.setIcon(new ImageIcon(new URL("http://veerex.googlecode.com/svn/trunk/src/memo_icon.jpg")));
		      			sibling.memo_button.setText("List Memos");
    				} catch (MalformedURLException e) {
    				}
		      		str = new String(((JButton)evt.getSource()).getText());
				int j;
				for(j=0; j < 1024; j++) {
					if(buttons[j] == ((JButton)evt.getSource()) )
						break;
				}
				if(j < 1024) {
				System.out.println("j="+j);
				System.out.println("drive_index[j]"+drive_index[j]);
				System.out.println("drive letter"+drives[drive_index[j]]);

				
		      str = new String(drives[drive_index[j]]+"\\" + ((JButton)evt.getSource()).getText());
		      System.out.println(str);
				}
		      	dirmenu=true;
			}
		}
		
		if(openfile) {
		      System.out.println("action current"+str);
              		f = new File(str);
		}

	      if(f.isDirectory()) {
	      //if(!openfile) {
		      if(child != null) {
			      if(dirmenu) {
			if(last_clicked_file != null) {
			//	last_clicked_file.setForeground(this.getForeground());
			last_clicked_file.setContentAreaFilled(false);
				last_clicked_file.setBackground(this.getBackground());
			}
			last_clicked_file = ((JButton)evt.getSource());
			last_clicked_file.setBackground(Color.ORANGE);
			last_clicked_file.setContentAreaFilled(true);

			/*
			removeAll();
			validate();
			pane.revalidate();
			pane.repaint();
      			repaint();
			listfiles(str);
			repaint();
			*/
			      }
			      comp=child;
		      }
		      else {
		if(((JButton)evt.getSource() != last_clicked_file)) {
			if(last_clicked_file != null) {
			//	last_clicked_file.setForeground(this.getForeground());
				last_clicked_file.setBackground(this.getBackground());
				last_clicked_file.setContentAreaFilled(false);
			}
			last_clicked_file = ((JButton)evt.getSource());
			//last_clicked_file.setForeground(Color.BLACK);
			last_clicked_file.setBackground(Color.ORANGE);
			last_clicked_file.setContentAreaFilled(true);
			return;
		}
			//last_clicked_file.setForeground(Color.WHITE);
			last_clicked_file.setBackground(Color.ORANGE);
			/* doubleclick */

			      comp=this;
		      }
		        comp.last_clicked_file = null;

		//removeAll();
		//validate();
		//pane.revalidate();
		//pane.repaint();
      		//repaint();
		//listfiles(str);
		//JScrollPane.setViewport();
      		//repaint();
			comp.removeAll();
			comp.validate();
			comp.pane.revalidate();
			comp.pane.repaint();
      			comp.repaint();
			comp.listfiles(str);
			comp.repaint();
	      }
	      else {
		      if(!icon_menu) {
		if(((JButton)evt.getSource() != last_clicked_file)) {
			if(last_clicked_file != null) {
			//	last_clicked_file.setForeground(this.getForeground());
				last_clicked_file.setBackground(this.getBackground());
				last_clicked_file.setContentAreaFilled(false);
			}
			last_clicked_file = ((JButton)evt.getSource());
			//last_clicked_file.setForeground(Color.BLACK);
			last_clicked_file.setBackground(Color.ORANGE);
			last_clicked_file.setContentAreaFilled(true);
			return;
		}
			//last_clicked_file.setForeground(Color.WHITE);
			last_clicked_file.setBackground(Color.ORANGE);
			/* doubleclick */
		      }

		      try{
     		Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+str);
    		} catch (Exception e) {
    		}
	      }
	 }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

class SwingScrollBarExample extends JPanel{

  JLabel label;
  Oldfb1 oldfb1;
  JTextArea textarea;
	JScrollPane scrollPane;
  int type;

  public SwingScrollBarExample() {
    super(true);
  }

  public void setSwingScrollBarExample(int i) {
    label = new JLabel();
    setLayout(new BorderLayout());

    //JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
    //JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
    //JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL);
    //JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL);

    //hbar.setUnitIncrement(2);
    //hbar.setBlockIncrement(1);
	type = i;
	//if(type==0) {
    	//hbar.addAdjustmentListener(new MyAdjustmentListener());
    	//vbar.addAdjustmentListener(new MyAdjustmentListener());
    	//add(hbar, BorderLayout.SOUTH);
    	//add(vbar, BorderLayout.WEST);
	//}
    oldfb1 = new Oldfb1(type);
    add(oldfb1, BorderLayout.CENTER);
    //add(label, BorderLayout.CENTER);
  }

  public void addbuttons() {
    oldfb1.makeicons();
  }

  public void listfiles(String a, Oldfb1 mychild) {
	  textarea=new JTextArea();
	scrollPane = new JScrollPane(oldfb1);
	scrollPane.setViewportBorder(BorderFactory.createEmptyBorder(10,10,10,10));
	setPreferredSize(new Dimension(450, 110));
	scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
	add(scrollPane, BorderLayout.CENTER);
	oldfb1.setScrollPane(scrollPane);
	JScrollBar jsp = scrollPane.getVerticalScrollBar();
	jsp.setUnitIncrement(20);
	oldfb1.setChild(mychild);
	if(type > 1)
    		oldfb1.listfiles(a);
  }

  public void addlisting(String a) {
	  oldfb1.listfiles(a);
  }


  public void setFrame(JFrame vframe) {
	  	oldfb1.setFrame(vframe);
  }

  public void updatefiles(String a) {
	  oldfb1.listfiles(a);
  }

  public void resizeParentPane() {
	  setPreferredSize(new Dimension(450,110));
  }

  class MyAdjustmentListener implements AdjustmentListener {
    public void adjustmentValueChanged(AdjustmentEvent e) {
      //label.setText("    New Value is " + e.getValue() + "      ");
      //if(type!=1)
//	      oldfb1.listfiles();
      //repaint();
    }
  }

  public static void main(String s[]) {
    JFrame frame = new JFrame("Scroll Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new SwingScrollBarExample());
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}

public class Oldfb {
  public static void main(String args[]) {
    String title = (args.length == 0 ? "Veeru Browser" : args[0]);

    JFrame vFrame = new JFrame(title);
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //JComponent dashBoard= new JButton("Top");
    //JComponent dirTree = new JButton("Bottom");
    SwingScrollBarExample dirTree = new SwingScrollBarExample();
    SwingScrollBarExample blowUp = new SwingScrollBarExample();
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setOneTouchExpandable(true);



    final JSplitPane bottomSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    bottomSplit.setOneTouchExpandable(true);
    blowUp.setSwingScrollBarExample(3);
    blowUp.setFrame(vFrame);
    dirTree.setSwingScrollBarExample(2);
    dirTree.setFrame(vFrame);

    File [] drives = File.listRoots();
    for(int i=0; i < drives.length; i++) {
    	//dirTree.listfiles("C:\\",blowUp.oldfb1);
		if(i==0)
    		dirTree.listfiles(drives[i].toString(),blowUp.oldfb1);
		else
    		dirTree.addlisting(drives[i].toString());
		System.out.println(drives[i].toString());
		dirTree.oldfb1.drives[i] = new String(drives[i].toString());
    }
    blowUp.listfiles("",null);

    bottomSplit.setLeftComponent(dirTree);
    bottomSplit.setRightComponent(blowUp);

    SwingScrollBarExample dashBoard = new SwingScrollBarExample();
    dashBoard.setSwingScrollBarExample(1);
    dashBoard.listfiles("",blowUp.oldfb1);
    //iconTab.setSwingScrollBarExample(1);
    dashBoard.addbuttons();
    splitPane.setLeftComponent(dashBoard);

    splitPane.setRightComponent(bottomSplit);
	bottomSplit.setDividerLocation(300);
    dirTree.oldfb1.sibling = dashBoard.oldfb1;
    //Oldfb1.makeicons(dashBoard);
    //Oldfb1.listfiles(dirTree);
    ActionListener oneActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        splitPane.resetToPreferredSizes();
      }
    };
    //((JButton) dirTree).addActionListener(oneActionListener);
    ActionListener anotherActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        splitPane.setDividerLocation(10);
        splitPane.setContinuousLayout(true);
      }
    };
    //((JButton) dashBoard).addActionListener(anotherActionListener);
    vFrame.getContentPane().add(splitPane, BorderLayout.CENTER);
    //Rectangle bounds = vFrame.getMaximizedBounds();
    //vFrame.setBounds(bounds);
    //vFrame.setSize(300, 150);
    vFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
    vFrame.setVisible(true);

  }
}


class JButtons extends JFrame {

  public JButtons(String str) {
    super(str);
  }
  void makeButtons(JFrame frame) {
	  Container content = frame.getContentPane();
    WindowUtilities.setNativeLookAndFeel();
    addWindowListener(new ExitListener());
    content.setBackground(Color.white);
    content.setLayout(new FlowLayout());
    ImageIcon cup = new ImageIcon("http://veerex.googlecode.com/files/pdf_icon.jpg");
    JButton button2 = new JButton(cup);
    content.add(button2);
    ImageIcon cup1 = new ImageIcon("http://veerex.googlecode.com/files/photo_icon.jpg");
    JButton button3 = new JButton(cup1);
    content.add(button3);
    ImageIcon cup2 = new ImageIcon("http://veerex.googlecode.com/files/docs_icon.jpg");
    JButton button4 = new JButton(cup2);
    button4.setHorizontalTextPosition(SwingConstants.CENTER);
    content.add(button4);
    //pack();
    setVisible(true);
  }
}

class ExitListener extends WindowAdapter {
  public void windowClosing(WindowEvent event) {
    System.exit(0);
  }
}


/** A few utilities that simplify using windows in Swing.
 *  1998-99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
 */

class WindowUtilities {

  /** Tell system to use native look and feel, as in previous
   *  releases. Metal (Java) LAF is the default otherwise.
   */

  public static void setNativeLookAndFeel() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) {
//      System.out.println("Error setting native LAF: " + e);
    }
  }

  public static void setJavaLookAndFeel() {
    try {
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch(Exception e) {
//      System.out.println("Error setting Java LAF: " + e);
    }
  }

   public static void setMotifLookAndFeel() {
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
    } catch(Exception e) {
//      System.out.println("Error setting Motif LAF: " + e);
    }
  }

  /** A simplified way to see a JPanel or other Container.
   *  Pops up a JFrame with specified Container as the content pane.
   */

  public static JFrame openInJFrame(Container content,
                                    int width,
                                    int height,
                                    String title,
                                    Color bgColor) {
    JFrame frame = new JFrame(title);
    frame.setBackground(bgColor);
    content.setBackground(bgColor);
    frame.setSize(width, height);
    frame.setContentPane(content);
    frame.addWindowListener(new ExitListener());
    frame.setVisible(true);
    return(frame);
  }

  /** Uses Color.white as the background color. */

  public static JFrame openInJFrame(Container content,
                                    int width,
                                    int height,
                                    String title) {
    return(openInJFrame(content, width, height, title, Color.white));
  }

  /** Uses Color.white as the background color, and the
   *  name of the Container's class as the JFrame title.
   */

  public static JFrame openInJFrame(Container content,
                                    int width,
                                    int height) {
    return(openInJFrame(content, width, height,
                        content.getClass().getName(),
                        Color.white));
  }
}

class VeryOldfb{

	public VeryOldfb() { ; };
    public static void main(String[] args) {
	    int i;
//        System.out.println("Hello World!"); // Display the string.
	String a = "C:\\";
	File f = new File(a);
	String [] files;	
	files = f.list();
	//for(i=0; i < files.length; i++)
//		System.out.println(files[i]);
    }

    public static void ShowFiles(JFrame frame) {
	    int i;
	String a = "C:\\";
	File f = new File(a);
	String [] files;	
	files = f.list();
	for(i=0; i < files.length; i++) {
        	//JLabel label = new JLabel("<html><body><br>"+files[i]+"<br></body></html>");
        	//frame.getContentPane().add(label);
	}
    }
}

//class alter_Oldfb implements ActionListener {
//
//    private static String labelPrefix = "Number of button clicks: ";
//    private int numClicks = 0;
//    final JLabel label = new JLabel(labelPrefix + "0    ");
//
//    //Specify the look and feel to use.  Valid values:
//    //null (use the default), "Metal", "System", "Motif", "GTK+"
//    final static String LOOKANDFEEL = null;
//
//    public Component createComponents() {
//        JButton button = new JButton("I'm a Swing button!");
//        button.setMnemonic(KeyEvent.VK_I);
//        button.addActionListener(this);
//        label.setLabelFor(button);
//
//        /*
//         * An easy way to put space between a top-level container
//         * and its contents is to put the contents in a JPanel
//         * that has an "empty" border.
//	 */
//        JPanel pane = new JPanel(new GridLayout(0, 1));
//        pane.add(button);
//        pane.add(label);
//        pane.setBorder(BorderFactory.createEmptyBorder(
//                                        30, //top
//                                        30, //left
//                                        10, //bottom
//                                        30) //right
//                                        );
//
//        return pane;
//    }
//
//    public void actionPerformed(ActionEvent e) {
//        numClicks++;
//        label.setText(labelPrefix + numClicks);
//    }
//
//    private static void initLookAndFeel() {
//        String lookAndFeel = null;
//
//        if (LOOKANDFEEL != null) {
//            if (LOOKANDFEEL.equals("Metal")) {
//                lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
//            } else if (LOOKANDFEEL.equals("System")) {
//                lookAndFeel = UIManager.getSystemLookAndFeelClassName();
//            } else if (LOOKANDFEEL.equals("Motif")) {
//                lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
//            } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
//                lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
//            } else {
//                System.err.println("Unexpected value of LOOKANDFEEL specified: "
//                                   + LOOKANDFEEL);
//                lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
//            }
//
//            try {
//                UIManager.setLookAndFeel(lookAndFeel);
//            } catch (ClassNotFoundException e) {
//                System.err.println("Couldn't find class for specified look and feel:"
//                                   + lookAndFeel);
//                System.err.println("Did you include the L&F library in the class path?");
//                System.err.println("Using the default look and feel.");
//            } catch (UnsupportedLookAndFeelException e) {
//                System.err.println("Can't use the specified look and feel ("
//                                   + lookAndFeel
//                                   + ") on this platform.");
//                System.err.println("Using the default look and feel.");
//            } catch (Exception e) {
//                System.err.println("Couldn't get specified look and feel ("
//                                   + lookAndFeel
//                                   + "), for some reason.");
//                System.err.println("Using the default look and feel.");
//                e.printStackTrace();
//            }
//        }
//    }
//
//    /**
//     * Create the GUI and show it.  For thread safety,
//     * this method should be invoked from the
//     * event-dispatching thread.
//     */
//    private static void createAndShowGUI() {
//        //Set the look and feel.
//        initLookAndFeel();
//
//        //Make sure we have nice window decorations.
//        JFrame.setDefaultLookAndFeelDecorated(true);
//
//        //Create and set up the window.
//        JFrame frame = new JFrame("SwingApplication");
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
//        alter_Oldfb app = new alter_Oldfb();
//        Component contents = app.createComponents();
//        frame.getContentPane().add(contents, BorderLayout.CENTER);
//
//        //Display the window.
//        frame.pack();
//        frame.setVisible(true);
//    }
//
//    public static void main(String[] args) {
//        //Schedule a job for the event-dispatching thread:
//        //creating and showing this application's GUI.
//        javax.swing.SwingUtilities.invokeLater(new Runnable() {
//            public void run() {
//                createAndShowGUI();
//            }
//        });
//    }
//}
//
//
//



